<template>
    <div class="login-container">
        <!-- 登录框 -->
        <div class="login-box">
            <!-- 头像 -->
            <div class="avater">
                <img src="../../assets/imgs/avater.png" alt="">
            </div>
            <!-- 表单区域 -->
            <div class="form-box">
                <el-form :model="user" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="用户名" prop="username">
                        <el-input v-model="user.username"></el-input>
                    </el-form-item>
                    <el-form-item label="用户名" prop="password">
                        <el-input v-model="user.password"></el-input>
                    </el-form-item>
                    <el-form-item prop="verifyCode">
                        <div class="verifyCode_box">
                            <el-input v-model="user.verifyCode" placeholder="请输入手机验证码" prefix-icon="el-icon-mobile" class="verifyCode"></el-input>
                            <img src="../../assets/imgs/yzm.png" alt="" class="verifyCode_img">
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
                        <el-button @click="resetForm('ruleForm')">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                user: {
                    username: 'ange',
                    password: '123456',
                    verifyCode: '',
                },
                rules: {
                    username: [
                        { required: true, message: '请输入用户名称', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '请输入登录密码', trigger: 'blur' }
                    ],
                }
            }
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                if (valid) {
                    //登录之后跳转主页面
                    this.$router.push('/home');
                } else {
                    console.log('error submit!!');
                    return false;
                }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        },
    }
</script>

<style lang="less" scoped>
    .login-container{
        height: 100%;
        background-color: #FFE4E1;

        .login-box{
            height: 350px;
            width: 600px;
            background-color: #FFFFFF;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);

            .avater{
                width: 130px;
                height: 130px;
                background-color: #fff;
                border-radius: 50%;
                padding: 10px;
                margin: -65px auto;
                img{
                    width: 100%;
                    height: 100%;
                    border-radius: 50%;
                    background-color: #eeeeee;
                    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
                }
            }

            .form-box{
                padding: 30px;
                margin-top: 50px;
                .verifyCode_box{
                    display: flex;
                    .el-input{
                        flex: 2;
                    }
                    img{
                        flex: 1;
                    }
                }
            }
        }
    }
</style>